//
//  VisitorLoginView.swift
//  Sina Weibo
//
//  Created by 斩尘 on 15/10/6.
//  Copyright © 2015年 陈帅. All rights reserved.
//

import UIKit
//MARK: 代理方法
protocol VisitorLoginViewDelegate : NSObjectProtocol{

    func visitorWillRegister()
    
    func visitorWillLogin()
    
    
}

class VisitorLoginView: UIView {

    weak var visitorViewDelegate : VisitorLoginViewDelegate?
    
    @IBOutlet weak var iconView: UIImageView!

    @IBOutlet weak var smallIcon: UIImageView!
    
    @IBOutlet weak var tipLabel: UILabel!
    
//    MARK: 设置图片
    func setUIInfo (imageName name : String, tipText : String, isHome : Bool = false){
    
        iconView.image = UIImage(named: name)
        tipLabel.text = tipText
        
        smallIcon.hidden = !isHome
        if isHome {
        
            startAnimation()
        }
        
    }
//    MARK: 旋转动画
    private func startAnimation() {
    
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        
        anim.repeatCount = MAXFLOAT
        
        anim.duration = 15
        
        anim.toValue = 2 * M_PI
        
//        当动画页面处于非活跃状态下,默认会移除图层动画
        anim.removedOnCompletion = false 
        
        smallIcon.layer.addAnimation(anim, forKey: nil)
        
        
    }
    
    
    
    
    @IBAction func loginAction(sender: AnyObject) {
        

        visitorViewDelegate?.visitorWillLogin()
        
    }

    @IBAction func registerAction(sender: AnyObject) {
    

        visitorViewDelegate?.visitorWillRegister()
    }
}
